
import { Controller, Get, OnModuleInit, Injectable, Param, Query, Inject, Put, Post, Delete, Body } from '@nestjs/common';
import { School } from 'src/models/school.model';
import { ClientGrpc, Client} from '@nestjs/microservices';
import { SchoolService } from './types.d/school.service';
import { SchoolClientOption } from 'src/clients/school.rpc.client';
import { SchoolRespMessage } from './types.d/school.response.message';
import { ListSchoolRespMessage } from './types.d/listschool.response.message';


@Controller('school')
export class SchoolController implements OnModuleInit{
  
  
  onModuleInit(): void {

    this.schoolService = this.client.getService<SchoolService>("SchoolRPCService")
  }
  

  @Client(SchoolClientOption)
  private client: ClientGrpc
  private schoolService: SchoolService

  @Get(':id')
  queryOneSchool(@Param('id') id: string): Promise<SchoolRespMessage>{
    return this.schoolService.queryOneSchool({id: +id})
  }

  @Get()
  queryListSchool(@Param('id') id: string):  Promise<ListSchoolRespMessage>{
    return this.schoolService.queryListSchool({id: +id})
  }

  @Put()
  createOneSchool(@Body('name',) name: string,): Promise<SchoolRespMessage>{
    return this.schoolService.createOneSchool({name})
  }

  @Post(':id')
  patchOneSchool(@Param('id') id: string,@Body('name',) name: string,):Promise<SchoolRespMessage>{
    return this.schoolService.patchOneSchool({id: +id,name})
  }

  @Delete(':id')
  deleteOneSchool(@Param('id') id: string): Promise<SchoolRespMessage>{
    
    return this.schoolService.deleteOneSchool({id: +id})
  }
}